package com.dlc.shop.api.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dlc.shop.bean.model.OrderRefundIntervention;
import com.dlc.shop.common.response.ServerResponseEntity;
import com.dlc.shop.common.util.PageParam;
import com.dlc.shop.security.common.util.AuthUserContext;
import com.dlc.shop.service.OrderRefundInterventionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 订单退款介入记录
 *
 * @author LGH
 * @date 2023-10-26 15:52:39
 */
@RestController
@RequestMapping("/p/orderRefundIntervention")
@Tag(name = "订单退款介入记录")
@AllArgsConstructor
public class OrderRefundInterventionController {

    private final OrderRefundInterventionService orderRefundInterventionService;

    @PostMapping("/saveInterventionVoucher")
    @Operation(summary = "添加介入凭证", description = "添加介入凭证")
    public ServerResponseEntity<Void> saveInterventionVoucher(@RequestBody @Valid OrderRefundIntervention orderRefundIntervention) {
        orderRefundIntervention.setSysType(AuthUserContext.getSysType());
        orderRefundIntervention.setBizId(AuthUserContext.getShopId());
        orderRefundInterventionService.saveInterventionVoucher(orderRefundIntervention);
        return ServerResponseEntity.success();
    }

    @GetMapping("/page")
    @Operation(summary = "获取订单退款介入记录列表", description = "分页获取订单退款介入记录列表")
    public ServerResponseEntity<IPage<OrderRefundIntervention>> getOrderRefundInterventionPage(PageParam<OrderRefundIntervention> page, @ParameterObject OrderRefundIntervention orderRefundIntervention) {
        return ServerResponseEntity.success(orderRefundInterventionService.page(page, new LambdaQueryWrapper<OrderRefundIntervention>()));
    }

    @GetMapping("/info/{refundIntervertionId}")
    @Operation(summary = "获取订单退款介入记录", description = "根据refundIntervertionId获取订单退款介入记录")
    @Parameter(name = "refundIntervertionId", description = "订单退款介入记录", required = true)
    public ServerResponseEntity<OrderRefundIntervention> getById(@PathVariable("refundIntervertionId") Long refundIntervertionId) {
        return ServerResponseEntity.success(orderRefundInterventionService.getById(refundIntervertionId));
    }

    @PostMapping
    @PreAuthorize("@pms.hasPermission('seckill:orderRefundIntervention:save')")
    @Operation(summary = "保存订单退款介入记录", description = "保存订单退款介入记录")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid OrderRefundIntervention orderRefundIntervention) {
        return ServerResponseEntity.success(orderRefundInterventionService.save(orderRefundIntervention));
    }

    @PutMapping
    @PreAuthorize("@pms.hasPermission('seckill:orderRefundIntervention:update')")
    @Operation(summary = "更新订单退款介入记录", description = "更新订单退款介入记录")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid OrderRefundIntervention orderRefundIntervention) {
        return ServerResponseEntity.success(orderRefundInterventionService.updateById(orderRefundIntervention));
    }

    @DeleteMapping("/{refundIntervertionId}")
    @PreAuthorize("@pms.hasPermission('seckill:orderRefundIntervention:delete')")
    @Operation(summary = "删除订单退款介入记录", description = "根据订单退款介入记录id删除订单退款介入记录")
    @Parameter(name = "refundIntervertionId", description = "订单退款介入记录", required = true)
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long refundIntervertionId) {
        return ServerResponseEntity.success(orderRefundInterventionService.removeById(refundIntervertionId));
    }
}
